// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

var rp = require('request-promise');

// 云函数入口函数
exports.main = async (event, context) => {
  let city = encodeURIComponent(event.city);
  return rp(`https://free-api.heweather.com/s6/weather?key=d469334ef67548578d65268f148b046f&location=${encodeURIComponent(city)}`)
    .then(function (res) {
      // console.log(res);
      res = JSON.parse(res);
      return res;
    })
    .catch(function (err) {
      console.error(err);
    });
}